package sicau.carManager.result;

import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author ITcz
 * @Data 2021-02-06 - 17:15
 */
public class R extends HashMap<String, Object> {

    private static final String MSG = "msg";

    private static final String CODE = "code";

    public R(){
        put(MSG, HttpStatus.OK.getReasonPhrase());
        put(CODE, HttpStatus.OK.value());
    }

    public static R error(int code, String msg){
        R r = new R();
        r.put(MSG, msg);
        r.put(CODE, code);
        return r;
    }

    public static R error(String msg){
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
    }

    public static R error(){
        return error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
    }

    public static R ok(){
        return new R();
    }

    public static R ok(String msg){
        return ok().put(MSG, msg);
    }

    public static R ok(Map<String, Object> map){
        R r = new R();
        r.putAll(map);
        return r;
    }

    @Override
    public R put(String key, Object object){
        super.put(key, object);
        return this;
    }


}
